package com.geekaca.d07.test_stream;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest4 {
    public static void main(String[] args) {

        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三丰", "张无忌", "周芷若", "赵敏", "张强","张三丰");

        Stream<String> stream = names.stream().filter(e -> e.startsWith("张"));
//        List<String> 张 = names.stream().filter(e -> e.startsWith("张")).toList();
        List<String> zhanglist = stream.collect(Collectors.toList());
        System.out.println(zhanglist);

        Stream<String> stream2 = names.stream().filter(e -> e.startsWith("张"));
        Set<String> nameset = stream2.collect(Collectors.toSet());
        System.out.println("不重复");
        System.out.println(nameset);

        Stream<String> stream3 = names.stream().filter(e -> e.startsWith("张"));

        Object[] objects = stream3.toArray();
        System.out.println(Arrays.toString(objects));
    }
}
